#include <sys/types.h>
#include <unistd.h>
#include <errno.h>
#include <stdio.h>
#include <stdlib.h>

int main(void){
  pid_t pid;
  int i, n = 5, status, global = 0;


  for(i=0; i<n; i++){
    pid = fork();
    int status;

    switch(pid){
      case -1: //fork error
        perror("fork error");
        printf("errno value= %d\n", errno);
        exit(-1);
      break;

      case 0: //proceso hijo
        global++;
        exit(EXIT_SUCCESS);
      break;

      default:
      printf(" ");
    }
  }
  while(pid!= wait(&status));
    printf("Global = %d\n", global);

  return 0;
}
